package com.qf.shixi.service.impl;

import com.qf.shixi.dao.SubjectDao;
import com.qf.shixi.entity.Subject;
import com.qf.shixi.service.SubjectService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Subject)表服务实现类
 *
 * @author
 * @since 2021-10-12 10:03:32
 */
@Service("subjectService")
public class SubjectServiceImpl implements SubjectService {
    @Resource
    private SubjectDao subjectDao;

    /**
     * 新增数据
     *
     * @param subject 实例对象
     * @return 实例对象
     */
    @Override
    public Subject insert(Subject subject) {
        this.subjectDao.insert(subject);
        return subject;
    }

    /**
     * 修改数据
     *
     * @param subject 实例对象
     * @return 实例对象
     */
    @Override
    public Subject update(Subject subject) {
        this.subjectDao.update(subject);
        return this.queryById(subject.getSuId());
    }

    /**
     * 通过主键删除数据
     *
     * @param suId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer suId) {
        return this.subjectDao.deleteById(suId) > 0;
    }



    @Override
    public List<Subject> queryByType(String type) {
        Subject subject = new Subject();
        if(!type.equals("recommend")){
            subject.setTitle(type);
        }
        return subjectDao.queryByConditions(subject);
    }

    @Override
    public Subject queryById(Integer suId) {
        return this.subjectDao.queryById(suId);
    }

    @Override
    public List<String> querySuName() {
        List<String> sunames = subjectDao.querySuName();
        return sunames;
    }
}
